package com.junzhiit.nengji.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.bainaeco.framework.base.dao.AbstractBaseDAO;
import com.bainaeco.framework.common.jdbc.StatementParameter;
import com.junzhiit.nengji.dao.GoodsSystemTypeDAO;
import com.junzhiit.nengji.model.GoodsSystemType;
import com.junzhiit.nengji.model.enums.Is;

@Repository
public class GoodsSystemTypeDAOImpl extends AbstractBaseDAO<GoodsSystemType> implements GoodsSystemTypeDAO {

	@Override
	public List<String> getGoodsSystemTypeByGoodsId(String Id) {
		StringBuffer sql = new StringBuffer();
		StatementParameter params = new StatementParameter();
		sql.append("select system_type_id from goods_system_type where goods_id = ? and is_delete = ? ");
		params.setString(Id);
		params.setInt(Is.NO.toIntValue());
		return super.queryForStrings(sql.toString(), params);
	}

	@Override
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public boolean updateIsDelete(String systemTypes, String goodsId,Integer status) {
		StringBuffer sql = new StringBuffer();
		StatementParameter params = new StatementParameter();
		sql.append("update goods_system_type set is_delete = ? where goods_id = ?");
		params.setInt(Is.YES.toIntValue());
		params.setString(goodsId);
		if(systemTypes != null && !"".equals(systemTypes)){
			sql.append(" and system_type_id in ("+systemTypes+")");
		}
		return super.updateForBoolean(sql.toString(), params);
	}
	
	
	@Override
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public boolean deleteByGoodsId(String GoodsId) {
		StringBuffer sql = new StringBuffer();
		sql.append("delete from goods_system_type where goods_id=?");
		
		StatementParameter params=new StatementParameter();
		params.setString(GoodsId);
		
		return super.updateForBoolean(sql.toString(), params);
	}

}
